package com.tanhua.controller;

import com.tanhua.exception.BusinessException;
import com.tanhua.interceptor.UserHolder;
import com.tanhua.model.UserInfo;
import com.tanhua.server.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;
    @PostMapping("/loginReginfo")
    private ResponseEntity loginReginfo(@RequestBody UserInfo userInfo) {
       /* boolean verifyToken = JwtUtils.verifyToken(token);
        if (!verifyToken){
            return  ResponseEntity.status(401).body(null);
        }*/
       /* Claims claims = JwtUtils.getClaims(token);
         Integer id = (Integer) claims.get("id");*/
         userInfo.setId(Long.valueOf(UserHolder.getUserId()));
         userInfoService.save(userInfo);
        return ResponseEntity.ok(null);
    }
    @PostMapping("/loginReginfo/head")
    public  ResponseEntity head(MultipartFile headPhoto) throws IOException, BusinessException {
       /* boolean verifyToken = JwtUtils.verifyToken(token);
        if (!verifyToken){
            return  ResponseEntity.status(401).body(null);
        }*/

       /* Claims claims = JwtUtils.getClaims(token);
        Integer id = (Integer) claims.get("id");*/
            //传入照片的地址，用户的id
            userInfoService.updateHead(headPhoto, UserHolder.getUserId());
            return ResponseEntity.ok(null);
    }
}
